package com.ggy.ggyaiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;
//配置类-暂时使用云配置
//@Configuration
public class LoveAppVectorStoreConfig {
    @Resource
    private LoveAppDocumentLoader loveAppDocumentLoader;
    @Resource
    private MyTokenTextSplitter myTokenTextSplitter;
    @Resource
    private MyKeywordEnricher myKeywordEnricher;
    //@Bean
    VectorStore loveAppVectorStore(EmbeddingModel embeddingModel) {
        //先加载一个SimpleVectorStore
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(embeddingModel).build();
        //加载文档
        List<Document> documents = loveAppDocumentLoader.loadMarkDowns();
        //自主切分
        //List<Document> splitDocuments = myTokenTextSplitter.splitCustomized(documents);
        List<Document> documents1 = myKeywordEnricher.enrichDocuments(documents);
        //转存
        simpleVectorStore.add(documents1);
        return simpleVectorStore;
    }

}
